<?php
class MPD
{
	static $Channels = Array();
	
	public static function add($chan, Array $data, Array $users){
		sort($users);
		$uHash = md5($chan.json_encode($users));		
		self::$Channels[$uHash]["chan"] 	= $chan;
		self::$Channels[$uHash]["data"][] 	= $data;
		self::$Channels[$uHash]["users"] 	= $users;
	}
	
	public static function send(){
		//if(count(self::$Channels) > 0){
			$rpl = DB::getRPL();
			$ret = array();
		// Расскидываем сообщения по юзерам
			foreach(self::$Channels as $key => $chan){
				$ret[] = $chan;
				$rpl->send(Array($chan["chan"] => Realplexor::get_cursor()), Array("action"=>"MULTI_DATA", "data" => $chan["data"]),  $chan["users"]);
				unset(self::$Channels[$key]);
			}		
			return $ret;
		//}
	}

}

?>